import reg from "./reg";

//验证手机号码
export const validatePhone = (rule, value, callback) => {
  if (!value) {
    callback(new Error('请输入手机号码'));
  } else if (!reg.phone.test(value)) {
    callback(new Error('手机号格式不对'));
  } else {
    callback();
  }
};

//验证验证码
export const validateCode = (rule, value, callback) => {
  if (!value) {
    callback(new Error('请输入验证码'));
  } else {
    callback();
  }
};
//QQ邮箱验证
export const validateQQEmail = (rule, value, callback) => {
  if (!value) {
    callback(new Error("请填写QQ邮箱"));
  } else if (!reg.qqEmail.test(value)) {
    callback(new Error("QQ邮箱格式错误"));
  } else {
    callback();
  }
};

//邮箱验证
export const validateEmail = (rule, value, callback) => {
  if (!value) {
    callback(new Error("请填写邮箱"));
  } else if (!reg.email.test(value)) {
    callback(new Error("邮箱格式错误"));
  } else {
    callback();
  }
};
